import 'package:flutter/foundation.dart';

@immutable
class HttpCode {
  final int rawValue;
  final String describe;
  const HttpCode(this.rawValue, this.describe);

  @override bool operator ==(Object other) => (other is HttpCode) && (other.rawValue == rawValue);
  @override int get hashCode => rawValue;

  // 1xx
  static const acontinue = HttpCode(100, "continue");
  static const switchingProtocols = HttpCode(101, "switchingProtocols");
  static const processing = HttpCode(102, "processing");

  // 2xx
  static const ok = HttpCode(200, "ok");
  static const created = HttpCode(201, "created");
  static const accepted = HttpCode(202, "accepted");
  static const nonAuthoritativeInformation =
      HttpCode(203, "nonAuthoritativeInformation");
  static const noContent = HttpCode(204, "noContent");
  static const resetContent = HttpCode(205, "resetContent");
  static const partialContent = HttpCode(206, "partialContent");
  static const multiStatus = HttpCode(207, "multiStatus");
  static const alreadyReported = HttpCode(208, "alreadyReported");
  static const imUsed = HttpCode(226, "imUsed");

  // 3xx
  static const multipleChoices = HttpCode(300, "multipleChoices");
  static const movedPermanently = HttpCode(301, "movedPermanently");
  static const found = HttpCode(302, "found");
  static const seeOther = HttpCode(303, "seeOther");
  static const notModified = HttpCode(304, "notModified");
  static const useProxy = HttpCode(305, "useProxy");
  static const temporaryRedirect = HttpCode(307, "temporaryRedirect");
  static const permanentRedirect = HttpCode(308, "permanentRedirect");

  // 4xx
  static const badRequest = HttpCode(400, "badRequest");
  static const unauthorized = HttpCode(401, "unauthorized");
  static const paymentRequired = HttpCode(402, "paymentRequired");
  static const forbidden = HttpCode(403, "forbidden");
  static const notFound = HttpCode(404, "notFound");
  static const methodNotAllowed = HttpCode(405, "methodNotAllowed");
  static const notAcceptable = HttpCode(406, "notAcceptable");
  static const proxyAuthenticationRequired =
      HttpCode(407, "proxyAuthenticationRequired");
  static const requestTimeout = HttpCode(408, "requestTimeout");
  static const conflict = HttpCode(409, "conflict");
  static const gone = HttpCode(410, "gone");
  static const lengthRequired = HttpCode(411, "lengthRequired");
  static const preconditionFailed = HttpCode(412, "preconditionFailed");
  static const payloadTooLarge = HttpCode(413, "payloadTooLarge");
  static const uriTooLong = HttpCode(414, "uriTooLong");
  static const unsupportedMediaType = HttpCode(415, "unsupportedMediaType");
  static const rangeNotSatisfiable = HttpCode(416, "rangeNotSatisfiable");
  static const expectationFailed = HttpCode(417, "expectationFailed");
  static const imATeapot = HttpCode(418, "imATeapot");
  static const misdirectedRequest = HttpCode(421, "misdirectedRequest");
  static const unprocessableEntity = HttpCode(422, "unprocessableEntity");
  static const locked = HttpCode(423, "locked");
  static const failedDependency = HttpCode(424, "failedDependency");
  static const upgradeRequired = HttpCode(426, "upgradeRequired");
  static const preconditionRequired = HttpCode(428, "preconditionRequired");
  static const tooManyRequests = HttpCode(429, "tooManyRequests");
  static const requestHeaderFieldsTooLarge =
      HttpCode(431, "requestHeaderFieldsTooLarge");
  static const unavailableForLegalReasons =
      HttpCode(451, "unavailableForLegalReasons");

  // 5xx
  static const internalServerError = HttpCode(500, "internalServerError");
  static const notImplemented = HttpCode(501, "notImplemented");
  static const badGateway = HttpCode(502, "badGateway");
  static const serviceUnavailable = HttpCode(503, "serviceUnavailable");
  static const gatewayTimeout = HttpCode(504, "gatewayTimeout");
  static const httpVersionNotSupported =
      HttpCode(505, "httpVersionNotSupported");
  static const variantAlsoNegotiates = HttpCode(506, "variantAlsoNegotiates");
  static const insufficientStorage = HttpCode(507, "insufficientStorage");
  static const loopDetected = HttpCode(508, "loopDetected");
  static const notExtended = HttpCode(510, "notExtended");
  static const networkAuthenticationRequired =
      HttpCode(511, "networkAuthenticationRequired");

  HttpCode init(int value, {String? describe}) {
    switch (value) {
      case 100:
        return HttpCode.acontinue;
      case 101:
        return HttpCode.switchingProtocols;
      case 102:
        return HttpCode.processing;

      case 200:
        return HttpCode.ok;
      case 201:
        return HttpCode.created;
      case 202:
        return HttpCode.accepted;
      case 203:
        return HttpCode.nonAuthoritativeInformation;
      case 204:
        return HttpCode.noContent;
      case 205:
        return HttpCode.resetContent;
      case 206:
        return HttpCode.partialContent;
      case 207:
        return HttpCode.multiStatus;
      case 208:
        return HttpCode.alreadyReported;
      case 226:
        return HttpCode.imUsed;

      case 300:
        return HttpCode.multipleChoices;
      case 301:
        return HttpCode.movedPermanently;
      case 302:
        return HttpCode.found;
      case 303:
        return HttpCode.seeOther;
      case 304:
        return HttpCode.notModified;
      case 305:
        return HttpCode.useProxy;
      case 307:
        return HttpCode.temporaryRedirect;
      case 308:
        return HttpCode.permanentRedirect;

      case 400:
        return HttpCode.badRequest;
      case 401:
        return HttpCode.unauthorized;
      case 402:
        return HttpCode.paymentRequired;
      case 403:
        return HttpCode.forbidden;
      case 404:
        return HttpCode.notFound;
      case 405:
        return HttpCode.methodNotAllowed;
      case 406:
        return HttpCode.notAcceptable;
      case 407:
        return HttpCode.proxyAuthenticationRequired;
      case 408:
        return HttpCode.requestTimeout;
      case 409:
        return HttpCode.conflict;
      case 410:
        return HttpCode.gone;
      case 411:
        return HttpCode.lengthRequired;
      case 412:
        return HttpCode.preconditionFailed;
      case 413:
        return HttpCode.payloadTooLarge;
      case 414:
        return HttpCode.uriTooLong;
      case 415:
        return HttpCode.unsupportedMediaType;
      case 416:
        return HttpCode.rangeNotSatisfiable;
      case 417:
        return HttpCode.expectationFailed;
      case 418:
        return HttpCode.imATeapot;
      case 421:
        return HttpCode.misdirectedRequest;
      case 422:
        return HttpCode.unprocessableEntity;
      case 423:
        return HttpCode.locked;
      case 424:
        return HttpCode.failedDependency;
      case 426:
        return HttpCode.upgradeRequired;
      case 428:
        return HttpCode.preconditionRequired;
      case 431:
        return HttpCode.requestHeaderFieldsTooLarge;
      case 451:
        return HttpCode.unavailableForLegalReasons;

      case 500:
        return HttpCode.internalServerError;
      case 501:
        return HttpCode.notImplemented;
      case 502:
        return HttpCode.badGateway;
      case 503:
        return HttpCode.serviceUnavailable;
      case 504:
        return HttpCode.gatewayTimeout;
      case 505:
        return HttpCode.httpVersionNotSupported;
      case 506:
        return HttpCode.variantAlsoNegotiates;
      case 507:
        return HttpCode.insufficientStorage;
      case 508:
        return HttpCode.loopDetected;
      case 510:
        return HttpCode.notExtended;
      case 511:
        return HttpCode.networkAuthenticationRequired;
      default:
        return HttpCode(value, describe ?? "");
    }
  }
}
